package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.example.demo.po.Others;
import com.example.demo.service.OtherService;


@Controller
@RequestMapping("/admin")
public class AdminOtherController {
	
	@Autowired	
	private OtherService otherService;
	
	@RequestMapping(value="/adminOther.action",method=RequestMethod.GET)
	public String indext(Model model){
		
		List<Others> otherList = otherService.selectAll();
		
		model.addAttribute("otherList", otherList); 
		
		return "admin/other/otherList";
		
	}
	
	@RequestMapping(value="/toEditOther.action",method=RequestMethod.GET)
	public String toEdit(Model model,Integer id){
		
		if(id!=null){
			
			Others other=otherService.selectById(id);
			
			model.addAttribute("other", other);
		}
		
		return "admin/other/edit";
		
	}
	
	@RequestMapping(value="/editOther.action",method=RequestMethod.POST)
	public String edit(Others other){
		
		if(other.getId()!=null){
			otherService.update(other);
		}else{			
			otherService.insert(other);
		}
		
		return "redirect:adminOther.action";		
	}
	
	@RequestMapping(value="/deleteOther.action",method=RequestMethod.GET)
	public String delete(Integer id){
		
		otherService.delete(id);
		return "redirect:adminNews.action";
		
	}

}
